<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="showtime"></div>
	</body>
	<script>
		var showtime = function() {
			var nowtime = new Date(), //获取当前时间
				endtime = new Date("2022/8/8"); //定义结束时间
			var lefttime = endtime.getTime() - nowtime.getTime(), //距离结束时间的毫秒数
				leftd = Math.floor(lefttime / (1000 * 60 * 60 * 24)), //计算天数
				lefth = Math.floor(lefttime / (1000 * 60 * 60) % 24), //计算小时数
				leftm = Math.floor(lefttime / (1000 * 60) % 60), //计算分钟数
				lefts = Math.floor(lefttime / 1000 % 60); //计算秒数
			return leftd + "天" + lefth + ":" + leftm + ":" + lefts; //返回倒计时的字符串
		}
		
		var div = document.getElementById("showtime");
		setInterval (function () {
		    div.innerHTML = showtime();
		}, 1000);  //反复执行函数本身
	</script>
</html>
